{extend name="base"/}
{block name="main"}
	<style>
		.k-use{cursor:Pointer}
		.k-use:hover{border: 1px solid #ff0000;}
	</style>
    <li class="list-group-item dobackup">
        <div class="row">
            <div class="col-xs-2">
                <button class="btn btn-default backup" type="submit" data-loading-text="loading...">立刻备份</button>
            </div>
            <div class="col-xs-10">
                <label class="col-xs-4 control-label">
                    <input id="fixow" type="checkbox" checked> 修复OW权限<br>还原时可选
                </label>
                <div class="input-group col-xs-8">
                    <span class="input-group-addon">sa密码</span>
                    <input class="form-control" id="sapassword" type="text" value="" placeholder="还原时输入">
                </div>
             </div>
        </div>
    </li>
	<div class="content">
        <table class="table">
          <thead>
            <tr>
              <th>备份</th>
              <th>大小</th>
              <th>备份时间</th>
              <th>操作</th>
            </tr>
          </thead>
          <tbody>
		{volist name='list' id='vo' empty='暂时没有数据'}
		<tr>
		    <td>{$vo.file|basename}</td>
			<td>{$vo.size|fileSizeConvert}</td>
			<td>{$vo.ctime|date="Y-m-d H:i:s",###}</td>
			<td>
			    <span class="label label-default backup" type="back" name="{$vo.file|basename}" data-loading-text="loading...">还原</span>
			    <span class="label label-success backup" type="del" name="{$vo.file|basename}" data-loading-text="loading...">删除</span>
			</td>
		</tr>
		{/volist}
          </tbody>
        </table>
	</div>
<script>
$(function() {
	$('.content,.dobackup').on('click','.backup',function(){
	    const elm=$(this);
	    const action=elm.attr('type');
	    const name=elm.attr('name');
	    const fixow=$('#fixow').is(':checked');
	    const sapassword=$('#sapassword').val();
	    if (action=='back' && !sapassword) return layer.tips('sa密码不能为空', '#sapassword',{tips: 3,tipsMore: true})
	    layer.msg('执行中，请等待...');
		$.ajax({
			url: 'kbackup',
			type: 'post',
			data: {action:action,name:name,fixow:fixow,sapassword:sapassword},
			async: true,
			dataType: "json",
			success: (data) => {layer.msg(data.msg,{time:1500,anim:6});},
			error: () => {},
			complete: () => {$('.content').load('backup.html .content');}
		});
	});
});
</script>
{/block}